#include <core/io.h>
#include <core/init.h>
#include <arch/arm.h>
#include <autoconf.h>
//#include <arch/at91sam926x.h>

// fixme
#define CONF_DM9000_PIO_RESET  PIOC
#define CONF_DM9000_PIN_RESET  (1 << 10)

#define CONF_DM9000_PIO_IRQ    PIOC
#define CONF_DM9000_PIN_IRQ    (1 << 11)


static __INIT__ int MW9261Init(void)
{
	UINT32 dwIntPin = 1 << 11;

	PLAT_INFO("MW9261 Board.\n");


	WriteLong(0x11, AT91SAM926X_PA_PMC + PMC_PCER);

	WriteLong(2 << 16 | 2, AT91SAM926X_PA_SMC + SMC_SETUP(2));
	WriteLong(0x08040804, AT91SAM926X_PA_SMC + SMC_PULSE(2));
	WriteLong(16 << 16 | 16, AT91SAM926X_PA_SMC + SMC_CYCLE(2));
	WriteLong(1 << 16 | 0x1103, AT91SAM926X_PA_SMC + SMC_MODE(2));

	At91PioConfOutput(CONF_DM9000_PIO_RESET, CONF_DM9000_PIN_RESET, 0);

	At91PioConfInput(CONF_DM9000_PIO_IRQ, CONF_DM9000_PIN_IRQ, 0);
	ReadLong(PIO_BASE(CONF_DM9000_PIO_IRQ) + PIO_ISR);

	//
	At91sam926xInitIrq();

	return 0;
}

PLAT_INIT(MW9261Init);

